package yunwo.cn.yzstation.presenter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import yunwo.cn.yzstation.R;
import yunwo.cn.yzstation.adapter.BaomingAdapter;
import yunwo.cn.yzstation.adapter.EndOrganAdapter;
import yunwo.cn.yzstation.adapter.ScreenAllAdapter;
import yunwo.cn.yzstation.adapter.TansAdapter;
import yunwo.cn.yzstation.api.IOrderModel;
import yunwo.cn.yzstation.api.IorderView;
import yunwo.cn.yzstation.base.Yzapp;
import yunwo.cn.yzstation.bean.OrderBean.StaTrackingFee;
import yunwo.cn.yzstation.bean.OrderBean.StaTrackingInfoDetail;
import yunwo.cn.yzstation.bean.PopupBean;
import yunwo.cn.yzstation.bean.Waybillbean;
import yunwo.cn.yzstation.bean.printBean.PrintLabelBean;
import yunwo.cn.yzstation.bean.printBean.PrintTicketBean;
import yunwo.cn.yzstation.model.OrderModel;
import yunwo.cn.yzstation.base.BasePresenter;
import yunwo.cn.yzstation.bean.DictionariesBean;
import yunwo.cn.yzstation.bean.EndOrganbean;
import yunwo.cn.yzstation.bean.OrderBean.StaTrackingInfo;
import yunwo.cn.yzstation.bean.YunfeiBean;
import yunwo.cn.yzstation.config.GoodsSP;
import yunwo.cn.yzstation.other.PickDialog;
import yunwo.cn.yzstation.other.ShowAnimationDialogUtil;
import yunwo.cn.yzstation.printer.NewSetPaintActivity;
import yunwo.cn.yzstation.printer.YHBPrintService;
import yunwo.cn.yzstation.utils.StringUtil;
import yunwo.cn.yzstation.utils.UIUtils;
import yunwo.cn.yzstation.view.activity.OrderActivity;
import yunwo.cn.yzstation.view.fregment.openorder.OrderFragment;

/**
 * Created by lao on 2017/9/11.
 */

public class OrderFragmentPersenter extends BasePresenter<IorderView> implements IOrderModel {

    private final SharedPreferences mPrinterShare;
    private final SharedPreferences.Editor mPrinteredit;
    private final SharedPreferences addressShare;
    private final SharedPreferences.Editor addresseditor;
    OrderActivity orderActivity;
    IorderView iorderView;
    OrderFragment orderFragment;
    private final OrderModel mOrderModel;


    public String mRebate1;
    public String mRemarks1;
    public String mVolume1;
    public String mWeight1;
    public String mAdvanceTransferCharges1;
    public String mStatement1;
    public String mProductName1;
    public String mPremium1;
    public String mPackName1;
    public String mDeliveryCharges1;
    public String mOtherCharges1;
    public String mServiceCharges1;
    public String mConsigneeAddress1;
    public String mFreight1;
    public String mConsigneePhone1;
    public String mConsigneeName1;
    public String mGoodsNumber1;
    public String numberFen;
    public int numberFen1 = 1;
    public int numberFen2 = 1;
    private final SharedPreferences.Editor mGoodsedit;
    private final GoodsSP mGoodsSP;
    private final SharedPreferences mDictionariesBean_sp;
    public List<String> mDictNamelist;
    public HashMap<String, String> mDictNameMap;
    public List<String> mJiaojielist;
    public HashMap<String, String> mJiaojiemap;
    private PickDialog mHalfScreenDialog;
    public List<String> mBaozhuanglist;
    public HashMap<String, String> mBaozhuangmap;
    public List<String> mPinmingList;
    public HashMap<String, String> mPinmingmap;


    StaTrackingInfo mOrderInfoBean = null;
    StaTrackingFee staTrackingFee = null;
    StaTrackingInfoDetail staTrackingInfoDetail = null;

    private final SharedPreferences mBaoFeiJiFei_sp;
    private final SharedPreferences.Editor mEdit;
    private List<EndOrganbean.DataBean> mEndOrganList;
    private List<EndOrganbean.DataBean.TransfersBean> mTransfersList;
    private String mGoodsSelfNumber;

    public OrderFragmentPersenter(OrderActivity orderActivity, IorderView iorderView,
                                  OrderFragment orderFragment, StaTrackingInfo mOrderInfoBean,
                                  StaTrackingFee staTrackingFee, StaTrackingInfoDetail staTrackingInfoDetail) {
        this.mOrderInfoBean = mOrderInfoBean;
        this.staTrackingFee = staTrackingFee;
        this.staTrackingInfoDetail = staTrackingInfoDetail;
        this.orderActivity = orderActivity;
        this.orderFragment = orderFragment;
        this.iorderView = iorderView;
        mOrderModel = new OrderModel(orderActivity, this);
        mGoodsedit = GoodsSP.getInstance().getEdit();
        mGoodsSP = GoodsSP.getInstance();
        mPrinterShare = orderActivity.getSharedPreferences("printerstate", Context.MODE_PRIVATE);
        mPrinteredit = mPrinterShare.edit();
        addressShare = orderActivity.getSharedPreferences("information_addresspiant", Context.MODE_PRIVATE);
        addresseditor = addressShare.edit();
        mDictionariesBean_sp = orderActivity.getSharedPreferences("SP_DICTION", Context.MODE_PRIVATE);
        String zidian = mDictionariesBean_sp.getString("zidian", "");
        mBaoFeiJiFei_sp = orderActivity.getSharedPreferences("feiyong", Context.MODE_PRIVATE);
        mEdit = mBaoFeiJiFei_sp.edit();
        if (!zidian.equals("")) {
            Gson gson = new Gson();
            mDictNamelist = new ArrayList<>();
            mDictNameMap = new HashMap<>();
            mJiaojielist = new ArrayList<>();
            mJiaojiemap = new HashMap<>();
            mBaozhuanglist = new ArrayList<>();
            mBaozhuangmap = new HashMap<>();
            mPinmingList = new ArrayList<>();
            mPinmingmap = new HashMap<>();

            DictionariesBean dictionariesBean = gson.fromJson(zidian, DictionariesBean.class);
            for (int i = 0; i < dictionariesBean.getData().size(); i++) {
                if (dictionariesBean.getData().get(i).getDictCode().equals("PAY_MEANS_TYPE")) {
                    mDictNamelist.add(dictionariesBean.getData().get(i).getDictName());
                    mDictNameMap.put(dictionariesBean.getData().get(i).getDictName(), dictionariesBean.getData().get(i).getDictValue());
                }
            }
            for (int i = 0; i < dictionariesBean.getData().size(); i++) {
                if (dictionariesBean.getData().get(i).getDictCode().equals("DELIVERY_TYPE")) {
                    mJiaojielist.add(dictionariesBean.getData().get(i).getDictName());
                    mJiaojiemap.put(dictionariesBean.getData().get(i).getDictName(), dictionariesBean.getData().get(i).getDictValue());
                }
            }
            for (int i = 0; i < dictionariesBean.getData().size(); i++) {
                if (dictionariesBean.getData().get(i).getDictCode().equals("PACK_NAME_TYPE")) {
                    mBaozhuanglist.add(dictionariesBean.getData().get(i).getDictName());
                    mBaozhuangmap.put(dictionariesBean.getData().get(i).getDictName(), dictionariesBean.getData().get(i).getDictValue());
                }
            }
            for (int i = 0; i < dictionariesBean.getData().size(); i++) {
                if (dictionariesBean.getData().get(i).getDictCode().equals("PRODUCT_NAME_TYPE")) {
                    mPinmingList.add(dictionariesBean.getData().get(i).getDictName());
                    mPinmingmap.put(dictionariesBean.getData().get(i).getDictName(), dictionariesBean.getData().get(i).getDictValue());
                }
            }
            for (int i = 0; i < dictionariesBean.getData().size(); i++) {
                if (dictionariesBean.getData().get(i).getDictCode().equals("PRMIUM_WAY")) {
                    mEdit.putString("dictValue", dictionariesBean.getData().get(i).getDictValue());
                    mEdit.commit();

                }
                if (dictionariesBean.getData().get(i).getDictCode().equals("GRATUITY_WAY")) {
                    mEdit.putString("xiaofei", dictionariesBean.getData().get(i).getDictValue());
                    mEdit.commit();
                }
                if (dictionariesBean.getData().get(i).getDictCode().equals("CREDIT_PROCEDURE_WAY")) {
                    mEdit.putString("daishou", dictionariesBean.getData().get(i).getDictValue());
                    mEdit.commit();
                }
                if (dictionariesBean.getData().get(i).getDictCode().equals("FREIGHT_WAY")) {
                    mEdit.putString("yunfei_zhongliang", dictionariesBean.getData().get(i).getDictValue());
                    mEdit.commit();
                }
                if (dictionariesBean.getData().get(i).getDictCode().equals("FREIGHT_WAY")) {
                    mEdit.putString("yunfei_tiji", dictionariesBean.getData().get(i).getDictValue());
                    mEdit.commit();
                }
            }
        }


        mOrderInfoBean.setPayMeansName(mDictNamelist.get(1));
        mOrderInfoBean.setPayMeansId(mDictNameMap.get(mDictNamelist.get(1)));
        mOrderInfoBean.setDeliveryName(mJiaojielist.get(1));
        mOrderInfoBean.setDeliveryId(mJiaojiemap.get(mJiaojielist.get(1)));


        mGoodsSP.setPayMeansName(mDictNamelist.get(1));
        mGoodsSP.setPayMeansId(mDictNameMap.get(mDictNamelist.get(1)));
        mGoodsSP.setDeliveryName(mJiaojielist.get(1));
        mGoodsSP.setdeliveryId(mJiaojiemap.get(mJiaojielist.get(1)));
        mGoodsedit.commit();
        cursorInitData();
    }

    public void setKeyvalue() {


        //回扣
        mRebate1 = orderFragment.mRebate.getText().toString().trim();
        //备注
        mRemarks1 = orderFragment.mRemarks.getText().toString().trim();
        //体积
        mVolume1 = orderFragment.mVolume.getText().toString().trim();
        //重量
        mWeight1 = orderFragment.mWeight.getText().toString().trim();
        //垫中转费
        mAdvanceTransferCharges1 = orderFragment.mAdvanceTransferCharges.getText().toString().trim();

        //品名
        mProductName1 = orderFragment.mProductName.getText().toString().trim();
        //保费
        mPremium1 = orderFragment.mPremium.getText().toString().trim();
        //包名
        mPackName1 = orderFragment.mPackName.getText().toString().trim();
        //送货费
        mDeliveryCharges1 = orderFragment.mDeliveryCharges.getText().toString().trim();
        //其他费
        mOtherCharges1 = orderFragment.mOtherCharges.getText().toString().trim();
        //服务费
        mServiceCharges1 = orderFragment.mServiceCharges.getText().toString().trim();
        //收货人地址
        mConsigneeAddress1 = orderFragment.mConsigneeAddress.getText().toString().trim();
        //运费
        mFreight1 = orderFragment.mFreight.getText().toString().trim();
        //收货人地话
        mConsigneePhone1 = orderFragment.mConsigneePhone.getText().toString().trim();
        //收货人
        mConsigneeName1 = orderFragment.mConsigneeName.getText().toString().trim();
        //件数
        mGoodsNumber1 = orderFragment.mGoodsNumber.getText().toString().trim();
        //自编号
        mGoodsSelfNumber = orderFragment.mGoodsSelfNumber.getText().toString().trim();


        mOrderInfoBean.setBeginOrganName(Yzapp.getInstance().getgetBeginOrgName());
        mOrderInfoBean.setBeginOrganId(Yzapp.getInstance().getBeginOrgId());

        mOrderInfoBean.setGoodsSelfNumber(mGoodsSelfNumber);
        mOrderInfoBean.setRemarks(mRemarks1);

        mOrderInfoBean.setProductName(mProductName1);
        mOrderInfoBean.setPackName(mPackName1);
        if (!StringUtil.isEmpty(mRebate1)) {
            staTrackingFee.setRebate(Double.valueOf(mRebate1));
        }
        if (!StringUtil.isEmpty(mVolume1)) {
            mOrderInfoBean.setVolume(Double.valueOf(mVolume1));
        }
        if (!StringUtil.isEmpty(mWeight1)) {
            mOrderInfoBean.setWeight(Double.valueOf(mWeight1));
        }
        if (!StringUtil.isEmpty(mAdvanceTransferCharges1)) {
            staTrackingFee.setAdvanceTransferCharges(Double.valueOf(mAdvanceTransferCharges1));
        }
        if (!StringUtil.isEmpty(mPremium1)) {
            staTrackingFee.setPremium(Double.valueOf(mPremium1));
        }
        if (!StringUtil.isEmpty(mServiceCharges1)) {
            staTrackingFee.setServiceCharges(Double.valueOf(mServiceCharges1));
        }
        if (!StringUtil.isEmpty(mGoodsNumber1)) {
            if (mGoodsNumber1.contains(".")) {
                Toast.makeText(orderActivity, "件数输入整数,别搞事情", Toast.LENGTH_SHORT).show();
                return;
            }
            mOrderInfoBean.setGoodsNumber(Integer.parseInt(mGoodsNumber1));
        }
        if (!StringUtil.isEmpty(mDeliveryCharges1)) {
            staTrackingFee.setDeliveryCharges(Double.valueOf(mDeliveryCharges1));
        }
        if (!StringUtil.isEmpty(mOtherCharges1)) {
            staTrackingFee.setOtherCharges(Double.valueOf(mOtherCharges1));
        }
        if (!StringUtil.isEmpty(mFreight1)) {
            staTrackingFee.setFreight(Double.valueOf(mFreight1));
        }





        staTrackingInfoDetail.setConsigneeName(mConsigneeName1);
        staTrackingInfoDetail.setConsigneePhone(mConsigneePhone1);
        staTrackingInfoDetail.setConsigneeAddress(mConsigneeAddress1);
        mOrderInfoBean.setTrackingFee(staTrackingFee);
        mOrderInfoBean.setTrackingInfoDetail(staTrackingInfoDetail);


        staTrackingInfoDetail.setTrackingNumber(mGoodsSP.getGoodsShare().getString("trackingNumber",""));
        String gnd = mGoodsSP.getGoodsShare().getString("gnd", "2.0");
        if (gnd.equals("\"\"") || gnd.equals("")) {
            gnd = "2.0";
        }
        mOrderInfoBean.setGnd(Double.valueOf(gnd));
        mOrderInfoBean.setTrackingNumber(mGoodsSP.getGoodsShare().getString("trackingNumber",""));

        mGoodsedit.commit();
        if (StringUtil.isEmpty(staTrackingInfoDetail.getTrackingNumber()) && StringUtil.isEmpty(mOrderInfoBean.getTrackingNumber())) {
            UIUtils.showToastSafe("获取运单号失败，正在重新获取");
            mOrderModel.getWayBill();
            return;
        }

        if (StringUtil.isEmpty(orderFragment.mBeginOrganName.getText().toString())) {
            UIUtils.showToastSafe("获取始发站失败");
            return;
        }
        if (StringUtil.isEmpty(orderFragment.mEndOrganName.getText().toString())) {
            UIUtils.showToastSafe("请选择目的站");
            return;
        }

        if (StringUtil.isEmpty(mConsigneeName1)) {
            UIUtils.showToastSafe("请输入联系人");
            return;
        }

        if (StringUtil.isEmpty(mFreight1)) {
            UIUtils.showToastSafe("请输入运费");
            return;
        }
        if (StringUtil.isEmpty(mProductName1)) {
            UIUtils.showToastSafe("请选择品名");
            return;
        }
        if (StringUtil.isEmpty(mPackName1)) {
            UIUtils.showToastSafe("请选择包装");
            return;
        }
        if (StringUtil.isEmpty(mGoodsNumber1)) {
            UIUtils.showToastSafe("请输入件数");
            return;
        }
        if (StringUtil.isEmpty(mWeight1) && StringUtil.isEmpty(mVolume1)) {
            UIUtils.showToastSafe("请输入重量或体积");
            return;
        }
        numberFen = orderFragment.mTipTagET.getText().toString().trim();  //标签
        String tipTagNu = orderFragment.mTipTagNumET.getText().toString().trim();  //打印份数
        int tipTagNuInt = 1;
        if (!StringUtil.isEmpty(orderFragment.mGoodsNumber1)) {
            numberFen1 = Integer.parseInt(orderFragment.mGoodsNumber1);
        } else {
            numberFen1 = 1;
        }
        if (!StringUtil.isEmpty(orderFragment.numberFen)) {
            numberFen2 = Integer.parseInt(orderFragment.numberFen);
        } else {
            numberFen2 = 1;
        }
        if (!StringUtil.isEmpty(tipTagNu)) {
            tipTagNuInt = Integer.parseInt(tipTagNu);
        } else {
            tipTagNuInt = 1;
        }
        if (numberFen2 > orderFragment.numberFen1) {
            UIUtils.showToastSafe("标签号不能大于总件数");
            return;
        } else {
            numberFen1 = orderFragment.numberFen1 - orderFragment.numberFen2 + 1;
            if (tipTagNuInt > orderFragment.numberFen1) {
                orderFragment.mTipTagNumET.setText(orderFragment.numberFen1 + "");
            }

        }
        orderFragment.countTotalFee();

        //判断打印机勾选

        if (!orderFragment.printLabelType || !orderFragment.printWaybillType) {

            boolean printstate = mPrinterShare.getBoolean("state", false);
            Log.d("printstate", String.valueOf(printstate));

            if (!printstate) {

                String address = addressShare.getString("address", "");
                String address1 = addressShare.getString("address1", "");
                if (StringUtil.isEmpty(address) && StringUtil.isEmpty(address1)) {
                    Toast.makeText(orderActivity, "请连接打印机", Toast.LENGTH_SHORT).show();
                    orderActivity.startActivity(new Intent(orderActivity, NewSetPaintActivity.class));
                    return;
                }

                mOrderModel.submit("",mOrderInfoBean);
//                mOrderFregmentPresenter.OpenOrder("");
//                initData("");
            } else {
                //// TODO: 2017/8/6 打印中

                Toast.makeText(orderActivity, "请等待打印完成", Toast.LENGTH_SHORT).show();
                return;
            }
        } else {
            mOrderModel.submit("1",mOrderInfoBean);

        }
    }

    public void initPayTypeDialogView(final PickDialog selectPayTypeDialog, final List<String> codeName,
                                      final HashMap<String, String> codeValue, TextView paymentTV, boolean ispay) {
        View view = selectPayTypeDialog.getView();
        ListView myListview = (ListView) view.findViewById(R.id.myListview);
        BaomingAdapter baomingAdapter = new BaomingAdapter(orderActivity, codeName, codeValue, selectPayTypeDialog, paymentTV, ispay ,mOrderInfoBean);
        myListview.setAdapter(baomingAdapter);
        TextView cancelTV = (TextView) view.findViewById(R.id.cancelTV);
        cancelTV.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectPayTypeDialog.dismiss();
            }
        });
    }


    public void screening(final String type) {
        mHalfScreenDialog = ShowAnimationDialogUtil.showDialog(orderActivity,
                R.layout.screen_view, Gravity.RIGHT, false, true);
        initHalfScreenView(mHalfScreenDialog, type);
    }


    private void initHalfScreenView(PickDialog dateDialog, final String type) {
        View view = dateDialog.getView();
        TextView titleTV = (TextView) view.findViewById(R.id.titleTV);
        ListView halfScreenLV = (ListView) view.findViewById(R.id.halfScreenLV);
        if ("3".equals(type)) {
            titleTV.setText("品名");
            ScreenAllAdapter screenAllAdapter = new ScreenAllAdapter(mPinmingList, orderActivity);
            halfScreenLV.setAdapter(screenAllAdapter);
            halfScreenLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    setDialogDismiss(mHalfScreenDialog);
                    orderFragment.mProductName.setText(mPinmingList.get(position));
                    GoodsSP.getInstance().setProductName(mPinmingList.get(position));
                    GoodsSP.getInstance().getEdit().commit();
                }
            });
        } else if ("4".equals(type)) {
            titleTV.setText("包装");
            ScreenAllAdapter screenAllAdapter = new ScreenAllAdapter(mBaozhuanglist, orderActivity);
            halfScreenLV.setAdapter(screenAllAdapter);
            halfScreenLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    setDialogDismiss(mHalfScreenDialog);
                    orderFragment.mPackName.setText(mBaozhuanglist.get(position));
                    GoodsSP.getInstance().setPackName(mBaozhuanglist.get(position));
                    GoodsSP.getInstance().getEdit().commit();
                }
            });
        } else if ("2".equals(type)) {
            titleTV.setText("目的站");
            EndOrganAdapter endOrganAdapter = new EndOrganAdapter(mEndOrganList, orderActivity);
            halfScreenLV.setAdapter(endOrganAdapter);
            halfScreenLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    setDialogDismiss(mHalfScreenDialog);


                    mOrderInfoBean.setEndOrganName(mEndOrganList.get(position).getEndOrganName());
                    mOrderInfoBean.setEndOrganId(mEndOrganList.get(position).getEndOrganId());
                    GoodsSP.getInstance().setEndOgranName(mEndOrganList.get(position).getEndOrganName());
                    GoodsSP.getInstance().setEndOgranid(mEndOrganList.get(position).getEndOrganId());
                    GoodsSP.getInstance().getEdit().commit();

                    orderFragment.mEndOrganName.setText(mEndOrganList.get(position).getEndOrganName());
                    mTransfersList = mEndOrganList.get(position).getTransfers();
                    if (mTransfersList.size() == 0) {
                        orderFragment.mTransferOrganName.setText("");
                        mOrderInfoBean.setTransferOrganName("");
                        mOrderInfoBean.setTransferOrganId("");

                        GoodsSP.getInstance().setTransferOrganid("");
                        GoodsSP.getInstance().setTransferOrganName("");
                        GoodsSP.getInstance().getEdit().commit();
                    }
                    if (mTransfersList.size() != 0) {
                        orderFragment.mTransferOrganName.setText(mTransfersList.get(0).getTransferOrganName());

                        mOrderInfoBean.setTransferOrganName(mTransfersList.get(0).getTransferOrganName());
                        mOrderInfoBean.setTransferOrganId(mTransfersList.get(0).getTransferOrganId());

                        GoodsSP.getInstance().setTransferOrganid(mTransfersList.get(0).getTransferOrganId());
                        GoodsSP.getInstance().setTransferOrganName(mTransfersList.get(0).getTransferOrganName());
                        GoodsSP.getInstance().getEdit().commit();
                    }
                }
            });
        } else if ("1".equals(type)) {
            titleTV.setText("中转站");
            TansAdapter tansAdapter = new TansAdapter(mTransfersList, orderActivity);
            halfScreenLV.setAdapter(tansAdapter);
            halfScreenLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    setDialogDismiss(mHalfScreenDialog);
                    orderFragment.mTransferOrganName.setText(mTransfersList.get(position).getTransferOrganName());

                    mOrderInfoBean.setTransferOrganName(mTransfersList.get(position).getTransferOrganName());
                    mOrderInfoBean.setTransferOrganId(mTransfersList.get(position).getTransferOrganId());

                    GoodsSP.getInstance().setTransferOrganid(mTransfersList.get(position).getTransferOrganId());
                    GoodsSP.getInstance().setTransferOrganName(mTransfersList.get(position).getTransferOrganName());
                    GoodsSP.getInstance().getEdit().commit();
                }
            });
        }


    }

    private void setDialogDismiss(PickDialog dateDialog) {
        if (dateDialog != null && dateDialog.isShowing()) {
            dateDialog.dismiss();
        }
    }

    private void cursorInitData() {
        orderFragment.mGoodsNumber.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                } else {
                    // 此处为失去焦点时的处理内容
                    orderFragment.mTipTagNumET.setText(orderFragment.mGoodsNumber.getText().toString().trim());

                }
            }
        });


    }

    public void getXiaoFei(String s) {

        mOrderModel.getXiaoFei(s);
    }

    @Override
    public void getXiaoFeiSuccess(int data) {
        iorderView.getXiaoFeiSuccess(data);
    }

    @Override
    public void getEndOrganSuccess(List<EndOrganbean.DataBean> response) {
        mEndOrganList = response;
    }

/*    @Override
    public void getEndOrganSuccess(EndOrganbean.DataBean response) {
//        mEndOrganList = response;
    }*/

 /*   @Override
    public void getEndOrganSuccess(EndOrganbean response) {
        mEndOrganList = response.getData();
    }
*/
    @Override
    public void getYunFeiSuccsee(YunfeiBean response) {
        iorderView.getYunFeiSuccsee(response);
    }

    @Override
    public void OpenOrderSuccess(String type, StaTrackingInfo orderInfoBean) {
        if (!StringUtil.isEmpty(type)) {
            iorderView.OpenOrderSuccess(type, orderInfoBean);
        }else {
            iorderView.OpenOrderSuccess(type, orderInfoBean);
            Double gnd = orderInfoBean.getGnd();

            print(orderInfoBean);
        }
    }

    private void print(StaTrackingInfo orderInfoBean) {
       /* String totalFeeString = goodsShare.getString("totalFeeString", "");

        if (StringUtil.isEmpty(totalFeeString)) {
            totalFeeString = "0 ";
        }
        String freight = mCarriage.getText().toString().trim();
        if (StringUtil.isEmpty(freight)) {
            freight = "0 ";
        }*/
        final String address = addressShare.getString("address", "");
        final String address1 = addressShare.getString("address1", "");
        String printername = addressShare.getString("printername", "XT4131");

        Log.d("vvvvvvvvvvvvv", "11111111111111");

        Intent intent = new Intent(orderActivity,YHBPrintService.class);
        Bundle bundle = new Bundle();
        bundle.putString("printername",printername);

        if (!orderFragment.printWaybillType) {
            bundle.putString(YHBPrintService.Start_address_ticket,address1);
        }else {
            bundle.putString(YHBPrintService.Start_address_ticket,"");
        }


        if (!orderFragment.printLabelType) {
            intent.putExtra(YHBPrintService.Start_address_label,address);
        }else {
            intent.putExtra(YHBPrintService.Start_address_label,"");
        }



        final PrintLabelBean labelBean = new PrintLabelBean();
        labelBean.setGroupName("云企集团");
        labelBean.setGnd(orderInfoBean.getGnd());
        labelBean.setCompanyName(Yzapp.getInstance().getgetBeginOrgName());
//        labelBean.setTrackNumber(waybillNumber);
        labelBean.setTrackNumber(orderInfoBean.getTrackingNumber());
        labelBean.setStartCity(Yzapp.getInstance().getgetBeginOrgName());
//        labelBean.setEndCity(goodsShare.getString("desCityName", ""));
        labelBean.setEndCity(orderInfoBean.getEndOrganName());   //到站城市
//        districtName
        labelBean.setTransStation(orderInfoBean.getTransferOrganName());
        labelBean.setSendMethod(orderInfoBean.getDeliveryName());
        labelBean.setNumber(String.valueOf(orderInfoBean.getGoodsNumber()));
        labelBean.setPosition(orderFragment.mTipTagET.getText().toString().trim());
        labelBean.setProductName(orderInfoBean.getProductName());
        labelBean.setUserName(orderInfoBean.getTrackingInfoDetail().getConsigneeName());
        labelBean.setSendPersonName(Yzapp.getInstance().getUserName());
        labelBean.setTime(getTime());
        bundle.putSerializable(YHBPrintService.Start_bean_label,labelBean);
//        intent.getExtras().putSerializable(YHBPrintService.Start_bean_label,labelBean);

        final PrintTicketBean ticketBean = new PrintTicketBean();
        ticketBean.setShangloufee(orderInfoBean.getTrackingFee().getUpstairsCharges()+"");
        ticketBean.setServiceFee(orderInfoBean.getTrackingFee().getServiceCharges()+"");
        ticketBean.setVolume(orderInfoBean.getVolume()+"");


        ticketBean.setWeight(orderInfoBean.getWeight()+"");
        ticketBean.setPackageName(orderInfoBean.getPackName());
        ticketBean.setShengjiaFee(orderInfoBean.getTrackingFee().getReputation()+"");
        ticketBean.setLandFee(orderInfoBean.getTrackingFee().getFloorCharges()+"");  //落地费
        ticketBean.setDeliveryFee(orderInfoBean.getTrackingFee().getDeliveryCharges()+"");//送货费
        ticketBean.setZhuangxieFee("");  //装卸费
        ticketBean.setTransFee(orderInfoBean.getTrackingFee().getAdvanceTransferCharges()+"");  // 中转费
        ticketBean.setOtherFee(orderInfoBean.getTrackingFee().getOtherCharges()+"");  //其他费
        ticketBean.setDaidianFee("");   //代垫贷款
        ticketBean.setDaikuanFee(orderInfoBean.getTrackingFee().getProcurationCharges()+""); //贷款
        ticketBean.setDaishouFee(orderInfoBean.getTrackingFee().getCollectMoney()+""); //代收贷款
        ticketBean.setBaoguanFee(orderInfoBean.getTrackingFee().getCustomsCharges()+""); //报关
        ticketBean.setTime(getTime());
      /*  boolean b = (mActivity.mCostFragment.mReceipt.getText().toString().equals("是")) ? true : false;
        boolean receipt = goodsShare.getBoolean("receipt", false);*/
        boolean b = orderInfoBean.getTrackingInfoDetail().getReceiptPay().equals("是") ? true : false;
        ticketBean.setHuidan(b);
        ticketBean.setTicket(orderFragment.mTicket.getText().toString());
        ticketBean.setGroupName("云企集团");
        ticketBean.setCompanyName(Yzapp.getInstance().getgetBeginOrgName());
        ticketBean.setTrackNumber(orderInfoBean.getTrackingNumber());
        ticketBean.setStartCity(Yzapp.getInstance().getgetBeginOrgName());
//        ticketBean.setEndCity(goodsShare.getString("desCityName", ""));
        ticketBean.setEndCity(orderInfoBean.getEndOrganName());    //到站城市
        ticketBean.setTransStation(orderInfoBean.getTransferOrganName());
        ticketBean.setServiceMethod(orderInfoBean.getDeliveryName());
        ticketBean.setNumber(orderInfoBean.getGoodsNumber()+"");
        ticketBean.setProductName(orderInfoBean.getProductName());

        ticketBean.setSendPersonPhone(orderInfoBean.getTrackingInfoDetail().getConsignorPhone());  //发货人电话号码
        ticketBean.setSendPersonName(orderInfoBean.getTrackingInfoDetail().getConsignorName());
        ticketBean.setSendPersonAddress(orderInfoBean.getTrackingInfoDetail().getConsignorAddress());
        Log.d("vvvvvvvvvvvvv", "3333333333333333");
        ticketBean.setUserName(orderInfoBean.getTrackingInfoDetail().getConsigneeName());
        ticketBean.setUserAddress(orderInfoBean.getTrackingInfoDetail().getConsigneeAddress());
        ticketBean.setUserPhone(orderInfoBean.getTrackingInfoDetail().getConsigneePhone());
        ticketBean.setFreight(orderInfoBean.getTrackingFee().getFreight()+"");
        ticketBean.setTotalFee(GoodsSP.getInstance().getGoodsShare().getString("totalFee",""));
        ticketBean.setRemarks(orderInfoBean.getRemarks());
        ticketBean.setPayment(orderInfoBean.getPayMeansName());
        ticketBean.setBaofeiFee(orderInfoBean.getTrackingFee().getPremium()+"");
        bundle.putSerializable(YHBPrintService.Start_bean_ticket,ticketBean);
//        intent.getExtras().putSerializable(YHBPrintService.Start_bean_ticket,ticketBean);
        intent.putExtras(bundle);
        Log.d("vvvvvvvvvvvvv", "44444444444");
        orderActivity.startService(intent);
        Log.d("vvvvvvvvvvvvv", "5555555555555555");
//        sendPrintStatus(intent);



    }


    public void getEndOrgan() {
        mOrderModel.getEndOrgan();
    }

    public void getYunFei(String s, String type) {
        mOrderModel.getYunFei(s, type);
    }

    @Override
    public void OpenOrderfailure(int code, String msg) {
        iorderView.OpenOrderfailure(code,msg);
    }

    @Override
    public void requestPopupConSuccess(List<PopupBean.DataBean> popupBean) {
        iorderView.requestPopupConSuccess(popupBean);
    }

    @Override
    public void getWayBillSuccess(Waybillbean.DataBean dataBean) {
        Toast.makeText(orderActivity, "运单号获取成功", Toast.LENGTH_SHORT).show();
        GoodsSP.getInstance().setWayBill(dataBean.getTrackingNumber());
        GoodsSP.getInstance().setGnd(dataBean.getGnd());
        GoodsSP.getInstance().getEdit().commit();
        staTrackingInfoDetail.setTrackingNumber(dataBean.getTrackingNumber());
        String gnd = dataBean.getGnd();
        if (gnd.equals("\"\"") || gnd.equals("")) {
            gnd = "2.0";
        }
        mOrderInfoBean.setGnd(Double.valueOf(gnd));
        mOrderInfoBean.setTrackingNumber(dataBean.getTrackingNumber());
    }

    public String getTime() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        Date curDate = new Date(System.currentTimeMillis());//获取当前时间
        String str = formatter.format(curDate);

        return str;
    }

    public void requestPopupCon(String type, String consignee) {
        mOrderModel.requestPopupCon(type,consignee);

    }
}
